package com.moarea.app.controller.system.login;

import com.moarea.app.lang.model.ResultObject;
import com.moarea.app.service.inter.login.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * 登录控制
 * <p>
 * jizhong
 * <p>
 * 2017-10-26
 */
@Controller
@RequestMapping(value = "/LoginController")
public class LoginController {

    @Autowired
    private ILoginService loginService;

    /**
     * 用户登录
     * <p>
     * jizhong
     * <p>
     * 2017-10-27
     *
     * @param request 参数
     *                USERNAME 用户名
     *                PASSWORD 密码
     * @param session HttpSession
     */
    @RequestMapping(value = "/login")
    @ResponseBody
    public ResultObject login(@RequestBody Map<String, String> param,HttpServletRequest request, HttpServletResponse response, HttpSession session) {
       return loginService.login(param,request, response, session);
    }


    /**
     * 获取当前登录用户的信息
     *
     * @param session HttpSession
     * @return 当前登录用户信息
     */
    @ResponseBody
    @RequestMapping(value = "/obtainUserInfo")
    public ResultObject obtainUserInfo(HttpSession session) {
        return loginService.obtainUserInfo(session);

    }

    /**
     * 退出登录
     *
     * @param session HttpSession
     * @return 当前登录用户信息
     */
    @ResponseBody
    @RequestMapping(value = "/exit")
    public ResultObject exit(HttpSession session) {
        return loginService.exit(session);

    }

    /**
     * 修改密码
     *
     * @param param   参数
     * @param session HttpSession
     * @return 结果
     */
    @ResponseBody
    @RequestMapping(value = "/changePassword")
    public ResultObject changePassword(@RequestBody Map<String, Object> param, HttpSession session) {
        return loginService.changePassword(param, session);

    }


}
